package cn.org.eshow.webapp.action;

import cn.org.eshow.bean.query.BaseQuery;
import cn.org.eshow.common.page.Page;
import cn.org.eshow.component.search.SearchManager;
import cn.org.eshow.model.*;
import cn.org.eshow.util.PageUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Results({ @Result(name = "blog", location = "/search/"),
		@Result(name = "user", location = "/search/user"),
		@Result(name = "service", location = "/search/service"),
		@Result(name = "topic", location = "/search/topic") })
public class SearchAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	public static final String USER = "user";

	@Autowired
	private SearchManager searchManager;
	private String keyword = "";
	private List<User> users;

	private BaseQuery query = new BaseQuery();

	public String user() throws Exception {
		if (StringUtils.isNotEmpty(keyword)) {
			Page<User> page = searchManager.search(User.class, keyword, query.getOffset(),
					query.pagesize, "username", "realname", "domain", "intro", "city", "province");
			users = page.getDataList();
			saveRequest("page", PageUtil.conversion(page));
		}
		return USER;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public BaseQuery getQuery() {
		return query;
	}

	public void setQuery(BaseQuery query) {
		this.query = query;
	}

}
